//
//  HNThreeGoodEvaDetailVC.m
//  优学荟管理系统
//
//  Created by edz on 2017/12/12.
//  Copyright © 2017年 星道三好. All rights reserved.
//

#import "HNThreeGoodEvaDetailVC.h"
#import "CourseEvaluateThreeGoodModel.h"
#import "CourseEvaluateView.h"
#import "CourseEvaluateAudioView.h"
#import "EMCDDeviceManager.h"
#import "MBSmartVideoView.h"
#import "MyHappyTimeVC.h"
#import "CourseEvaluateUploadFileTool.h"
#import "HNTeacgerEvaluateDetailModel.h"
#import <UIButton+WebCache.h>
#import "UIButton+ZYWebCaches.h"
/** 图片总量 */
static NSInteger const ImgCount = 3;

@interface HNThreeGoodEvaDetailVC ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
    
    __weak IBOutlet UIImageView *_StudentImg;
    __weak IBOutlet UILabel *_StudentName;
    __weak IBOutlet UILabel *_StudentLessonName;
    __weak IBOutlet NSLayoutConstraint *_StudentViewHeight;
    
    // 隐藏View
    __weak IBOutlet UIView *_HideView;
    // 菊花加载框
    __weak IBOutlet UIActivityIndicatorView *_Activity;
    
    /** 1、孩子三好评价 */
    // 好成绩View
    IBOutlet UIView *_GoodScore;
    // 好成绩View高度
    IBOutlet NSLayoutConstraint *_GoodScoreConstraint;
    // 好习惯View
    IBOutlet UIView *_GoodHabit;
    // 好习惯View高度
    IBOutlet NSLayoutConstraint *_GoodHabitConstraint;
    // 好素养View
    IBOutlet UIView *_GoodAttainment;
    // 好素养View高度
    IBOutlet NSLayoutConstraint *_GoodAttainmentConstraint;
    // scrollView的高度
    IBOutlet NSLayoutConstraint *_ScrollViewConstraint;
    
    // 上传按钮
    __weak IBOutlet UIButton *_UploadFileBtn;
    // 上传按钮的父视图
    __weak IBOutlet UIView *_UploadFileView;
    // 上传按钮的信息View
    __weak IBOutlet UIView *_UploadFileInfoView;
    // 上传按钮的左间距
    __weak IBOutlet NSLayoutConstraint *_UploadFileBtnLeft;
    
    /** 2、作业评价 */
    // 共性问题
    IBOutlet UITextView *_CommonProblem;
    // 共性问题的提示文字
    IBOutlet UILabel *_CommonProblemLabel;
    // 共性音频
    IBOutlet UIButton *_CommonAudio;
    // 共性音频的ID
    NSString *_CommonAudioID;
    // 个性问题
    IBOutlet UITextView *_PersonalProblem;
    // 个性问题的提示文字
    IBOutlet UILabel *_PersonalProblemLabel;
    // 个性音频
    IBOutlet UIButton *_PersonalAudio;
    // 个性音频的ID
    NSString *_PersonalAudioID;
    HNTeacgerEvaluateDetailModel *_DetailModel;
}
// 操作类
@property (nonatomic, strong) CourseEvaluateUploadFileTool *Tool;
// 相册摄像机
@property (nonatomic, strong) UIImagePickerController *ImagePicker;
// 三好问题列表
@property (nonatomic, strong) NSMutableArray <CourseEvaluateThreeGoodModel *>*ThreeGoodArr;
// 三好问题的选项 id-index
@property (nonatomic, strong) NSMutableArray <NSString *>*ThreeGoodSelectArr;
// 图片按钮
@property (nonatomic, strong)  NSMutableArray <UIButton *>*ImgBtns;
// 图片存储地直,@[@{key:Button}]
@property (nonatomic, strong) NSMutableArray *ImgArr;
// 那个图片的按钮
@property (nonatomic, strong) UIButton *TempButton;
// 视频的存储，@[@{Button.tag:@{@"url":url,@"img":img}}]
@property (nonatomic, strong) NSMutableArray *VideoDict;
@property (nonatomic, assign) NSInteger Tag;
/** 是否为个性或共性问题 */
@property (nonatomic, assign) BOOL IsCharacter;

@end

@implementation HNThreeGoodEvaDetailVC

// 白色导航栏
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(0, 0, 0)}];
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(255, 255, 255)] forBarMetrics:(UIBarMetricsDefault)];
}

// 导航栏恢复正常
- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:ColorRGB(255, 255, 255)}];
    [self.navigationController.navigationBar setBackgroundImage:[LLTools createImageWithColor:ColorRGB(47, 204, 138)] forBarMetrics:(UIBarMetricsDefault)];;

}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    _DetailModel = [HNTeacgerEvaluateDetailModel new];
    // 是否隐藏学生信息
    if ([[self.EnrollInfoIds componentsSeparatedByString:@","] count] > 1) {
        
        _StudentViewHeight.constant = 0;
    } else {
        
        [_StudentImg sd_setImageWithURL:[NSURL URLWithString:[self.ImgStr isKindOfClass:[NSNull class]] ? @"":self.ImgStr] placeholderImage:[UIImage imageNamed:@"image_user_default"]];
        _StudentLessonName.text = self.LessonName;
        _StudentName.text = self.Name;
    }
    
    self.title = @"三好动态评价";
    // 初始的tag
    self.Tag = 40000;
    
    // 更换成黑色的返回键
    self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTargat:self action:@selector(Pop) image:@"icon_back_student_sign" highImage:@"icon_back_student_sign"];
    
    // 查看是不是未完成的
    if (self.TempID && ![self.TempID isEqualToNumber:@0]) {
        
        
        [self RefreshDataOfWeiWanChengWithCallBack:^{
           
            [self UpdataUI];
            [_HideView removeFromSuperview];
        }];
    } else {
     
        [self RefreshDataWithCallBack:^{
                 [_HideView removeFromSuperview];
        }];

    }
}

#pragma mark - 网络请求
/**
 获取本页数据
 */
- (void)RefreshDataWithCallBack:(void (^)())CallBack {
    
    NSDictionary *Params = @{
                             @"lessonId"  :self.ID,
                             @"action"    :@"getTemplateDetialForCourse"
                             };
    [NetManager Get:LLBaseURL(@"yxhUser.do") Auth:YES Params:Params Success:^(id Obj) {
        
        // 创建对象
        if ([Obj[@"code"] isEqualToNumber:@1000])
        {
            if ([Obj[@"t"] isKindOfClass:[NSNull class]]) {
                return ;
            }
            NSLog(@"%@ %@ %@",LLBaseURL(@"yxhUser.do"),[AccountTool shareAccountTool].currentAccount.authCode,Params);
            // 好习惯
            NSArray *comment1Arr = Obj[@"t"][@"comment1"];
            [comment1Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                // 加入豪华午餐
                [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
            }];
           
            [self ConfigGoodHabit];
            
            // 好成绩
            NSArray *comment2Arr = Obj[@"t"][@"comment2"];
            [comment2Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                // 加入豪华午餐
                [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
            }];
             [self ConfigGoodSource];
            
            // 好素养
            NSArray *comment3Arr = Obj[@"t"][@"comment3"];
            [comment3Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                // 加入豪华午餐
                [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
            }];
            [self ConfigGoodAttainment];
            CallBack ? CallBack ():nil;
        }
        else
        {
            [_Activity stopAnimating];
            [MBProgressHUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        
        [_Activity stopAnimating];
        [MBProgressHUD showError:NetErr];
    }];
}

/** 获取未完成的网络数据 */
- (void)RefreshDataOfWeiWanChengWithCallBack:(void (^)())CallBack {
    
    NSDictionary *Params = @{
                             @"id"        :self.TempID,
                             @"action"    :@"getCommentTempDetailById",
                             @"isRead"    :@1
                             };
    [NetManager Get:LLBaseURLTeacher(@"aflatunLesson.do") Auth:YES Params:Params Success:^(id Obj) {
        
        // 创建对象
        if ([Obj[@"code"] isEqualToNumber:@1000])
        {
            _DetailModel = nil;
            _DetailModel = [[HNTeacgerEvaluateDetailModel alloc] init_HNObjectForKeys:Obj[@"t"]];
            NSLog(@"%@",_DetailModel.username);
            CallBack ? CallBack ():nil;
        }
        else
        {
            [_Activity stopAnimating];
            [MBProgressHUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        
        [_Activity stopAnimating];
        [MBProgressHUD showError:NetErr];
    }];
}

// 上传图片
- (void)UploadImg:(UIImage *)Img Complete:(void(^)(NSString *ImgName))Complete
{
    [MBProgressHUD showHUD];
    [NetManager UpdataImgWithURL:LLBaseURLTeacher(@"upload.do") Img:Img parameter:@{@"action":@"uploadimage"} success:^(id obj) {
        
        __block NSString *Str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
        
        dispatch_async(dispatch_get_main_queue(), ^{
            Str = [Str stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
            Str = [Str stringByReplacingOccurrencesOfString:@"\n" withString:@""];
            // 上传成功，设置图片
            Complete (Str);
        });
        
    } fail:^(NSError *error) {
        [MBProgressHUD showError:@"图片上传失败"];
    }];
}

/**
 添加数据
 */
- (void)RefreshDataForCommitEvaWithaction:(NSString *)action
                                imgFileId:(NSString *)imgFileId
                                 lessonId:(NSString *)lessonId
                                  comment:(NSString *)comment
                                subjectId:(NSString *)subjectId
                                childName:(NSString *)childName
                             commonFileId:(NSNumber *)commonFileId
                            enrollInfoIds:(NSString *)enrollInfoIds
                            commonProblem:(NSString *)commonProblem
                           personalFileId:(NSNumber *)personalFileId
                          personalProblem:(NSString *)personalProblem
                                      url:(NSString *)url
                                   urlImg:(NSString *)urlImg
{
    [HUD showHUD];
    NSDictionary *Params = @{
                             @"action"          :action?:@"",
                             @"imgFileId"       :imgFileId?:@"",
                             @"lessonId"        :lessonId?:@"",
                             @"comment"         :comment?:@"",
                             @"subjectId"       :subjectId,
                             @"uids"            :childName?:@"",
                             @"commonFileId"    :commonFileId?:@0,
                             @"enrollInfoIds"   :enrollInfoIds,
                             @"commonProblem"   :commonProblem?:@"",
                             @"personalFileId"  :personalFileId?:@0,
                             @"personalProblem" :personalProblem?:@"",
                             @"url" :url?:@"",
                             @"urlImg" :urlImg?:@""
                             };
    [NetManager Post:LLBaseURL(@"yxhUser.do") Auth:YES Params:Params Success:^(id Obj) {
        
        if ([Obj[@"code"] isEqualToNumber:@1000])
        {
            [HUD showSuccess:Obj[@"msg"]];
            self.PoP ? self.PoP():nil;
            _DetailModel = nil;
            [self performSelector:@selector(Pop) withObject:nil afterDelay:1.5];
        }
        else
        {
            [HUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        [HUD showError:NetErr];
    }];
}

- (void)CommitRefreshDataForCommitEvaWithaction:(NSString *)action
                                      imgFileId:(NSString *)imgFileId
                                       lessonId:(NSString *)lessonId
                                        comment:(NSString *)comment
                                      subjectId:(NSString *)subjectId
                                      childName:(NSString *)childName
                                   commonFileId:(NSNumber *)commonFileId
                                  enrollInfoIds:(NSString *)enrollInfoIds
                                  commonProblem:(NSString *)commonProblem
                                 personalFileId:(NSNumber *)personalFileId
                                personalProblem:(NSString *)personalProblem
                                            url:(NSString *)url
                                         urlImg:(NSString *)urlImg {
    [HUD showHUD];
    NSDictionary *Params = @{
                             @"action"          :action?:@"",
                             @"imgFileId"       :imgFileId?:@"",
                             @"lessonId"        :lessonId?:@"",
                             @"comment"         :comment?:@"",
                             @"subjectId"       :subjectId,
                             @"uids"            :childName?:@"",
                             @"commonFileId"    :commonFileId?:@0,
                             @"enrollInfoIds"   :enrollInfoIds,
                             @"commonProblem"   :commonProblem?:@"",
                             @"personalFileId"  :personalFileId?:@0,
                             @"personalProblem" :personalProblem?:@"",
                             @"url" :url?:@"",
                             @"urlImg" :urlImg?:@"",
                             @"id":self.TempID && ![self.TempID isEqualToNumber:@0] ? self.TempID:@0
                             };
    [NetManager Post:LLBaseURL(@"yxhUser.do") Auth:YES Params:Params Success:^(id Obj) {
        
        if ([Obj[@"code"] isEqualToNumber:@1000])
        {
            [HUD showSuccess:Obj[@"msg"]];
            self.PoP ? self.PoP() : nil;
            [self.navigationController popViewControllerAnimated:YES];
        }
        else
        {
            [HUD showError:Obj[@"msg"]];
        }
    } Fail:^(NSError *Error) {
        [HUD showError:NetErr];
    }];
}
    
    

/** 保存未完成的数据  */
- (void)RefreshDataOfWeiWanCheng {
    
    // 共性问题
    BOOL aEmoji =  [NSString stringContainsEmoji:_CommonProblem.text];
    
    if (aEmoji) return [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
    
    NSString *commonProblem  = _CommonProblem.text;
    
    
    
    
    
    
    
    // 个性图片ID
    NSString *personalFileId = _PersonalAudioID;
    
    
    BOOL bEmoji =  [NSString stringContainsEmoji:_PersonalProblem.text];
    
    
    if (bEmoji) return  [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
    
    // 个性问题
    NSString *personalProblem = _PersonalProblem.text;
    
    
    
    
    
    
    
    // 图片
    __block NSMutableArray *imgFileIdArr = [NSMutableArray array];
    [self.ImgArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 强转
        NSDictionary *Dict = (NSDictionary *)obj;
        // 强存
        [imgFileIdArr addObject:[[Dict allKeys] firstObject]];
    }];
    // 三好选项
    NSMutableArray *CommentArr = [NSMutableArray array];
    [self.ThreeGoodArr enumerateObjectsUsingBlock:^(CourseEvaluateThreeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [CommentArr addObject:[NSString stringWithFormat:@"%@-%@", obj.ID, [@(obj.FenShu)stringValue]]];
    }];
    NSString *comment = [CommentArr componentsJoinedByString:@","];
    // 图片数据
    NSString *imgFileId = [imgFileIdArr componentsJoinedByString:@","];
    // 课程ID
    NSString *lessonId = [self.ID stringValue];
    // 科目
    NSString *subjectId = @"0";
    // 共性图片ID
    NSString *commonFileId = _CommonAudioID;
    
    
    
    
    
    // 接口
    NSString *action = @"saveCommentTemp";
    // 学生账号
    NSString *childName = self.Uids;
    // 报名ID
    NSString *enrollInfoIds = self.EnrollInfoIds;
    
        [self CommitRefreshDataForCommitEvaWithaction:action
                                      imgFileId:imgFileId
                                       lessonId:lessonId
                                        comment:comment
                                      subjectId:subjectId
                                      childName:childName
                                   commonFileId:@([commonFileId integerValue])
                                  enrollInfoIds:enrollInfoIds
                                  commonProblem:commonProblem
                                 personalFileId:@([personalFileId integerValue])
                                personalProblem:personalProblem
                                            url:[self GetVideoStr:NO]
                                         urlImg:[self GetVideoStr:YES]];
    }


#pragma mark - Action
/** 退出 */
- (void)Pop {

    if (_DetailModel) {
        UIAlertController *Alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否保存临时数据?" preferredStyle:(UIAlertControllerStyleAlert)];
        [Alert addAction:[UIAlertAction actionWithTitle:@"保存" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
            [self RefreshDataOfWeiWanCheng];
        }]];
        [Alert addAction:[UIAlertAction actionWithTitle:@"放弃" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            [self.navigationController popViewControllerAnimated:YES];
            
        }]];
        [self presentViewController:Alert animated:YES completion:nil];
    } else {
        
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    
}

/**
 好成绩
 */
- (void)ConfigGoodSource
{
    [self MgrThreeGoodUI:@2 ThreeGoodView:_GoodScore ViewConstraint:_GoodScoreConstraint];
}

/**
 好习惯
 */
- (void)ConfigGoodHabit
{
    [self MgrThreeGoodUI:@1 ThreeGoodView:_GoodHabit ViewConstraint:_GoodHabitConstraint];
    
}

/**
 好素养
 */
- (void)ConfigGoodAttainment
{
    [self MgrThreeGoodUI:@3 ThreeGoodView:_GoodAttainment ViewConstraint:_GoodAttainmentConstraint];
}

/** 点击了图片事件 */
- (IBAction)ClickImageAction:(UIButton *)sender {
    
    self.TempButton = sender;
    [self AlertControllerOfTitle:@"请选择操作项" StringArr:@[@"图片上传", @"音频上传", @"视频上传"] CallBack:^(NSInteger Index, NSString *Str) {
        
        // 图片
        if ([Str isEqualToString:@"图片上传"] && Index == 0) {
            
            [self ClickImage:sender];
        }
        
        // 音频
        if ([Str isEqualToString:@"音频上传"] && Index == 1) {
         
            [self ClickAudio:sender];
        }
        
        // 视频
        if ([Str isEqualToString:@"视频上传"] && Index == 2) {
            
            [self ClickVideo:sender];
        }
    }];
}

/**
 处理了添加事件
 */
- (IBAction)MgrAdd
{
    
    // 共性问题
    BOOL aEmoji =  [NSString stringContainsEmoji:_CommonProblem.text];
    
    if (aEmoji) return [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
    
    NSString *commonProblem  = _CommonProblem.text;
    
    
    
    
    
    
    
    // 个性图片ID
    NSString *personalFileId = _PersonalAudioID;
    
    
    BOOL bEmoji =  [NSString stringContainsEmoji:_PersonalProblem.text];
    
    
    if (bEmoji) return  [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
    
    // 个性问题
    NSString *personalProblem = _PersonalProblem.text;
    
    
    
    
    
    
    
    // 图片
    __block NSMutableArray *imgFileIdArr = [NSMutableArray array];
    [self.ImgArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 强转
        NSDictionary *Dict = (NSDictionary *)obj;
        // 强存
        [imgFileIdArr addObject:[[Dict allKeys] firstObject]];
    }];
    // 三好选项
    NSString *comment = [self.ThreeGoodSelectArr componentsJoinedByString:@","];
    // 图片数据
    NSString *imgFileId = [imgFileIdArr componentsJoinedByString:@","];
    // 课程ID
    NSString *lessonId = [self.ID stringValue];
    // 科目
    NSString *subjectId = @"0";
    // 共性图片ID
    NSString *commonFileId = _CommonAudioID;
    
    
    
    
    
    // 接口
    NSString *action = @"saveComment";
    // 学生账号
    NSString *childName = self.Uids;
    // 报名ID
    NSString *enrollInfoIds = self.EnrollInfoIds;
    
    
    
    BOOL Right = [self.Tool JudgeWithaction:action
                                  imgFileId:imgFileId
                                   lessonId:lessonId
                                  subjectId:subjectId
                                  childName:childName
                               commonFileId:commonFileId
                              enrollInfoIds:@""
                              commonProblem:commonProblem
                             personalFileId:personalFileId
                            personalProblem:personalProblem
                         ThreeGoodSelectArr:self.ThreeGoodSelectArr
                       ThreeGoodSelectIndex:self.ThreeGoodArr.count];
    // 通过检查，提交数据
    if (Right)
    {
        if (self.ThreeGoodSelectArr.count < 9) {
            [HUD showError:@"请选择大于8条要素的模板进行评价"];
            
        }else {
            
            [self RefreshDataForCommitEvaWithaction:action
                                          imgFileId:imgFileId
                                           lessonId:lessonId
                                            comment:comment
                                          subjectId:subjectId
                                          childName:childName
                                       commonFileId:@([commonFileId integerValue])
                                      enrollInfoIds:enrollInfoIds
                                      commonProblem:commonProblem
                                     personalFileId:@([personalFileId integerValue])
                                    personalProblem:personalProblem
                                                url:[self GetVideoStr:NO]
                                             urlImg:[self GetVideoStr:YES]];
        }
        
    }
}

#pragma mark - Func
/**
 处理三好问题的UI
 */
- (void)MgrThreeGoodUI:(NSNumber *)Type ThreeGoodView:(UIView *)ThreeGoodView ViewConstraint:(NSLayoutConstraint *)ViewConstraint
{
    __block NSMutableArray <CourseEvaluateThreeGoodModel *>*Arr = [NSMutableArray array];
    // 循环看看
    [self.ThreeGoodArr enumerateObjectsUsingBlock:^(CourseEvaluateThreeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 要不要加入豪华午餐
        if ([obj.type isEqualToNumber:Type])
        {
            [Arr addObject:obj];
        }
    }];
    // UI
    [Arr enumerateObjectsUsingBlock:^(CourseEvaluateThreeGoodModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        // 不是相对应的就跳过
        if ([obj.type isEqualToNumber:Type])
        {
            // 好成绩的布局
            CourseEvaluateView *View = [CourseEvaluateView ConfigViewWithTitle:obj.content Y:0 SelectItem:^(NSString *Title, NSInteger Item) {
                // 判断成功后赋值临时str
                __block NSString *TempStr = @"";
                // 循环看看之前有没有加入
                [self.ThreeGoodSelectArr enumerateObjectsUsingBlock:^(NSString * _Nonnull Str, NSUInteger idx, BOOL * _Nonnull stop) {
                    // 取出
                    NSArray *Arr = [Str componentsSeparatedByString:@"-"];
                    // 第一个肯定是ID
                    NSString *Key = [Arr firstObject];
                    // 如果有就停止循环并将这个值放进临时str
                    if ([Key isEqualToString:[obj.ID stringValue]])
                    {
                        TempStr = Str;
                        *stop = YES;
                    }
                    // end
                }];
                // 判断数组里面是否有这个object，有就移除
                [self.ThreeGoodSelectArr containsObject:TempStr] ? [self.ThreeGoodSelectArr removeObject:TempStr]:nil;
                // 把选项保存起来
                [self.ThreeGoodSelectArr addObject:[NSString stringWithFormat:@"%@-%@",[obj.ID stringValue],[@(Item) stringValue]]];
                obj.FenShu = Item;
            }];
            View.Souce = [@(obj.FenShu) stringValue];
            [ThreeGoodView addSubview:View];
            // 布局
            [View mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo (ThreeGoodView.mas_top).offset (44*idx+44);
                make.right.equalTo (ThreeGoodView);
                make.left.equalTo (ThreeGoodView);
                make.height.equalTo (@44);
            }];
            // 高度
            ViewConstraint.constant += 44;
            _ScrollViewConstraint.constant += 44;
        }
    }];
}

/** 将需要展示的内容放进数组里，回调事件的顺序Index及相对应的Str */
- (void)AlertControllerOfTitle:(NSString *)Title StringArr:(NSArray <NSString *>*)StringArr CallBack:(void (^)(NSInteger Index, NSString *Str))CallBack {
    
    UIAlertController *Alert = [UIAlertController alertControllerWithTitle:Title message:nil preferredStyle:(UIAlertControllerStyleActionSheet)];
    [StringArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [Alert addAction:[UIAlertAction actionWithTitle:obj style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            CallBack ? CallBack(idx, obj) : nil;
        }]];
    }];
    [Alert addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]];
    [self presentViewController:Alert animated:YES completion:nil];
}



/** 移动上传按钮的左间距，YES增加 NO减 */
- (void)MoveUploadFileBtnLeftOfAdd:(BOOL)Add Button:(UIButton *)Button {

    
    // 移动固定的那个窗口
    [UIView animateWithDuration:0.3 animations:^{
    
        _UploadFileBtnLeft.constant = Add ? (_UploadFileBtnLeft.constant + _UploadFileBtn.frame.size.width + 15):(_UploadFileBtnLeft.constant - _UploadFileBtn.frame.size.width - 15);
        [_UploadFileBtn layoutIfNeeded];
        _UploadFileBtn.alpha = self.ImgBtns.count >= ImgCount && Add == YES ? 0:1;
        _UploadFileInfoView.alpha = self.ImgBtns.count >= ImgCount && Add == YES ? 0:1;
    }];
    
    
    // 位置变动
    if (Add == NO) {
        // 如果这个按钮在数组里存在就开始执行删除操作
        [self.ImgBtns containsObject:Button] ? [self.ImgBtns removeObject:Button]:nil;
        [Button removeFromSuperview];
        // 数组某个对象移除成功后重新将所有元素排版
        [self.ImgBtns enumerateObjectsUsingBlock:^(UIButton * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [obj mas_updateConstraints:^(MASConstraintMaker *make) {
                
                make.left.equalTo(_UploadFileView).offset(15 * (idx + 1) + (idx *_UploadFileBtn.frame.size.width));
            }];
        }];
        [UIView animateWithDuration:0.3 animations:^{
            [_UploadFileView layoutIfNeeded];
        }];
    }
    

    

}

/** 新建按钮的 */
- (UIButton *) CreatImgBtn:(UIImage *)Image {
    
    UIButton *Button = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [Button setBackgroundImage:Image forState:(UIControlStateNormal)];
    Button.tag = self.Tag;
    self.Tag ++;
    [Button addTarget:self action:@selector(DeleteImgBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [_UploadFileView addSubview:Button];
    [Button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.width.equalTo(_UploadFileBtn);
        make.left.equalTo(_UploadFileView.mas_left).offset(_UploadFileBtnLeft.constant);
    }];
    [self.ImgBtns addObject:Button];
    [self MoveUploadFileBtnLeftOfAdd:YES Button:nil];
    return Button;
}

/** 删除按钮 */
- (void)DeleteImgBtn:(UIButton *)Button {
    
    [self AlertControllerOfTitle:@"是否删除该文件?" StringArr:@[@"确定"] CallBack:^(NSInteger Index, NSString *Str) {
        
        // 临时保存地
        __block NSDictionary *TempDict = nil;
        // 在字典里看下有没有
        [self.ImgArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            // 提出字典里面的value
            NSArray *ValueArr = [(NSDictionary *)obj allValues];
            // value肯定是button
            UIButton *objButton = (UIButton *)[ValueArr firstObject];
            // 判断一下,如果存放就保存这个字典
            if (Button == objButton)
            {
                // 保存下来
                TempDict = (NSDictionary *)obj;
            }
        }];
        // 如果按钮是视频的话
        [self.VideoDict enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSInteger Index = [[[obj allKeys] firstObject] integerValue];
            if (Button.tag == Index) {
                
                [self.VideoDict removeObject:obj];
                *stop = YES;
            }
        }];
        // 检查这个TempDict，有值说明这个button已经有数据了,清除掉
        TempDict ? [self.ImgArr removeObject:TempDict] : nil;
        
        [self MoveUploadFileBtnLeftOfAdd:NO Button:Button];
        
    }];
    

}

/** YES:url NO:img */
- (NSString *)GetVideoStr:(BOOL)IsUrl {
    
    NSMutableArray *Arr = [NSMutableArray array];
    [self.VideoDict enumerateObjectsUsingBlock:^(NSDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSDictionary *Dict = [[obj allValues] firstObject];
        NSArray *arr =[Dict allValues];
        [Arr addObject: IsUrl ? [arr lastObject]:[arr firstObject]];
    }];
    return [Arr componentsJoinedByString:@","];
}

#pragma mark - 点击了图片上传
- (void)ClickImage:(UIButton *)Button {
    
    [self AlertControllerOfTitle:@"请选择图片选择方式" StringArr:@[@"拍摄", @"从相册中选择"] CallBack:^(NSInteger Index, NSString *Str) {
        if (Index == 0) {
            
            self.ImagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            [self presentViewController:self.ImagePicker animated:YES completion:nil];
        }
        
        if (Index == 1) {
            
            self.ImagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            [self presentViewController:self.ImagePicker animated:YES completion:nil];
        }
    }];
}
#pragma mark - 点击了音频上传
- (void)ClickAudio:(UIButton *)Button {
    
    // 得到音频的数据了
    [self UploadAVAudioComplete:^(NSString *ImgName) {
        
        ImgName = [ImgName stringByReplacingOccurrencesOfString:@"\r\n" withString:@""];
        ImgName = [ImgName stringByReplacingOccurrencesOfString:@"\n" withString:@""];
        
        if (self.TempButton == _PersonalAudio) {
            
            _PersonalAudioID = ImgName;
            _PersonalAudio.selected = YES;
            [_PersonalAudio setBackgroundImage:[UIImage imageNamed:@"btn_mp3"] forState:(UIControlStateSelected)];
        } else if (self.TempButton == _CommonAudio) {
            
            _CommonAudioID = ImgName;
            _CommonAudio.selected = YES;
            [_CommonAudio setBackgroundImage:[UIImage imageNamed:@"btn_mp3"] forState:(UIControlStateSelected)];
        } else {
        // 新建按钮的
        UIButton *Button = [self CreatImgBtn:[UIImage imageNamed:@"btn_mp3"]];
        // 加入数组
        [self.ImgArr addObject:@{ImgName:Button}];
        }
    }];
}

// 上传音频
- (void)UploadAVAudioComplete:(void(^)(NSString *ImgName))Complete
{
    [[UIApplication sharedApplication].keyWindow addSubview:[CourseEvaluateAudioView ConsumeSureWithClickCommit:^(BOOL IsSelect) {
        
        // 录音切换
        IsSelect ? [self MgrBeginAudio]:[self MgrCloseAudioComplete:Complete];
    }]];
}

/**
 开始录音
 */
- (void)MgrBeginAudio
{
    NSString *path = [[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"download/aaa"];
    
    [[EMCDDeviceManager sharedInstance] asyncStartRecordingWithFileName:path completion:^(NSError *error)
     {
     }];
    
}

/**
 停止录间并上传
 */
- (void)MgrCloseAudioComplete:(void(^)(NSString *ImgName))Complete
{
    [[EMCDDeviceManager sharedInstance] asyncStopRecordingWithCompletion:^(NSString *recordPath, NSInteger aDuration, NSError *error) {
        
        if (recordPath.length != 0) {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                [MBProgressHUD showHUD];
                [NetManager UpdataAudioWithURL:LLBaseURLTeacher(@"upload.do") FilePath:recordPath parameter:@{@"action":@"uploadimage"} success:^(id obj) {
                    
                    NSString *Str = [[NSString alloc] initWithData:obj encoding:NSUTF8StringEncoding];
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        // 上传成功，设置图片
                        Complete (Str);
                    });
                    
                } fail:^(NSError *error) {
                    [MBProgressHUD showError:@"音频上传失败"];
                }];
            });
        }
        
        // 主线程更新图片
        
        
    }];
}

#pragma mark - 点击了视频上传
- (void)ClickVideo:(UIButton *)Button {
    
    
    [self AlertControllerOfTitle:@"请选择视频选择方式" StringArr:@[@"拍摄", @"从相册中选择"] CallBack:^(NSInteger Index, NSString *Str) {
        if (Index == 0) {
            
            [self Action_GoCamera:Button];
        }
        
        if (Index == 1) {
            
            [self Action_Select:Button];
        }
    }];
}

/** 进入拍摄 */
- (void)Action_GoCamera:(UIButton *)Button{
    if (![self isSimulator]) {
        MBSmartVideoView *smart = [[MBSmartVideoView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        [self.navigationController.view addSubview:smart];
        __weak __typeof(&*self)weakSelf = self;
        [smart setFinishedRecordBlock:^(NSDictionary *info) {
            
            MyHappyTimeVC *vc = [MyHappyTimeVC new];
            
            vc.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
                
                [weakSelf VideoUploadSuccessUrlStr:urlStr urlImg:urlImg ImgPath:[[info objectForKey:@"videoURL"] description]];
                
            };
            
            
            vc.VideoPath = [[info objectForKey:@"videoURL"] description];
            [self.navigationController pushViewController:vc animated:YES];
            
        }];
    } else {
        NSLog(@"模拟器不支持小视频录制");
    }
}

// 按钮改变
- (void)VideoUploadSuccessUrlStr:(NSString *)urlStr urlImg:(NSString *)urlImg ImgPath:(NSString *)ImgPath {
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        UIButton *Button = [self CreatImgBtn:[self GetVideoPreViewImage:ImgPath]];
        // 视频的存储，@[@{Button.tag:@{@"url":url,@"img":img}}]
        [self.VideoDict addObject:@{@(Button.tag):@{@"url":urlStr,@"img":urlImg}}];
    });
    
}

/** 从相册中选择 */
- (void)Action_Select:(UIButton *)Button {
    
    UIImagePickerController *pickerImage = [[UIImagePickerController alloc] init];
    pickerImage.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    pickerImage.delegate = self;
    // 设定显示数据的类型，全部为视频
    pickerImage.mediaTypes = @[(NSString*)kUTTypeMovie,(NSString*)kUTTypeVideo,(NSString*)kUTTypeAudiovisualContent,(NSString*)kUTTypeAudio,(NSString*)kUTTypeQuickTimeMovie,(NSString*)kUTTypeMPEG,(NSString*)kUTTypeMPEG2Video,(NSString*)kUTTypeMPEG2TransportStream,(NSString*)kUTTypeMPEG4,(NSString*)kUTTypeMPEG4Audio,(NSString*)kUTTypeAppleProtectedMPEG4Audio,(NSString*)kUTTypeAppleProtectedMPEG4Video,(NSString*)kUTTypeAVIMovie,(NSString*)kUTTypeAudioInterchangeFileFormat,(NSString*)kUTTypeWaveformAudio,(NSString*)kUTTypeMIDIAudio];
    
    
    [pickerImage.navigationBar setBarTintColor:ColorRGB(58, 203, 140)];
    [pickerImage.navigationBar setTranslucent:NO];
    [pickerImage.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
    
    [self presentViewController:pickerImage animated:YES completion:nil];
}

/** 获取视频的第一帧的图片 */
- (UIImage*)GetVideoPreViewImage:(NSString *)Str
{
    AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:Str] options:nil];
    AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
    gen.appliesPreferredTrackTransform = YES;
    CMTime time = CMTimeMakeWithSeconds(0.0, 600);
    NSError *error = nil;
    CMTime actualTime;
    CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
    UIImage *img = [[UIImage alloc] initWithCGImage:image];
    CGImageRelease(image);
    return img;
}


#pragma mark - 相册代理
//适用获取所有媒体资源，只需判断资源类型
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
    
    //如果是视频资源
    NSURL *sourceURL = info[UIImagePickerControllerMediaURL];
    
    if (sourceURL != nil) {
        [picker dismissViewControllerAnimated:YES completion:^{
            
            NSString *Str = [sourceURL absoluteString];
            Str = [Str substringFromIndex:8];
            NSInteger   fileSize = [[NSFileManager defaultManager] attributesOfItemAtPath:Str error:nil].fileSize / 1024 / 1024;
            if (fileSize <= 0)
            {
                MyHappyTimeVC *VC = [[MyHappyTimeVC alloc] init];
                VC.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
                    
                    [self VideoUploadSuccessUrlStr:urlStr urlImg:urlImg ImgPath:Str];
                };
                
                VC.VideoPath = Str;
                [self.navigationController pushViewController:VC animated:YES];
            }
            else
            {
                NSString *Message = [NSString stringWithFormat:@"您选择的视频文件大小为%ld(兆)，上传需要花费较长时间，是否继续上传？",fileSize];
                // 跳转至视频上传
                UIAlertController *Alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:Message preferredStyle:(UIAlertControllerStyleAlert)];
                [Alert addAction:[UIAlertAction actionWithTitle:@"继续" style:(UIAlertActionStyleDestructive) handler:^(UIAlertAction * _Nonnull action) {
                    MyHappyTimeVC *VC = [[MyHappyTimeVC alloc] init];
                    
                    VC.urlBlock = ^(NSString *urlStr, NSString *urlImg) {
                        
                        [self VideoUploadSuccessUrlStr:urlStr urlImg:urlImg ImgPath:Str];
                    };
                    
                    
                    VC.VideoPath = Str;
                    [self.navigationController pushViewController:VC animated:YES];
                }]];
                [Alert addAction:[UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:nil]];
                [self presentViewController:Alert animated:YES completion:nil];
            }
        }];
    } else {
     
        // 图片
        [picker dismissViewControllerAnimated:YES completion:^{
            // 如果是图片
            UIImage *Img = info[UIImagePickerControllerOriginalImage];
            [self UploadImg:Img Complete:^(NSString *ImgName) {
                
                if (self.TempButton == _PersonalAudio) {
                    
                    _PersonalAudioID = ImgName;
                    _PersonalAudio.selected = YES;
                    [_PersonalAudio setBackgroundImage:Img forState:(UIControlStateSelected)];
                } else if (self.TempButton == _CommonAudio) {
                    
                    _CommonAudioID = ImgName;
                    _CommonAudio.selected = YES;
                    [_CommonAudio setBackgroundImage:Img forState:(UIControlStateSelected)];
                } else {
                    
                    // 新建按钮的
                    UIButton *Button = [self CreatImgBtn:Img];
                    // 加入数组
                    [self.ImgArr addObject:@{ImgName:Button}];
                }
            }];
            
        }];
    }
}

#pragma mark - TextView代理
- (void)textViewDidChange:(UITextView *)textView
{
    // 2100共性问题 2101个性问题
    // 共性
    if (textView == _CommonProblem)
    {

        BOOL isEmoji = [NSString stringContainsEmoji:textView.text];
        
        if (isEmoji) {
            [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
        }else{
            
            _CommonProblemLabel.hidden = textView.text.length > 0 ? YES:NO;
        }
    }
    // 个性
    if (textView == _PersonalProblem)
    {
        
        BOOL isEmojis = [NSString stringContainsEmoji:textView.text];
        
        if (isEmojis) {
            
            [self createAlertViewWithTitle:@"温馨提示" message:@"请输入合法的字符" preferredStyle:UIAlertControllerStyleAlert disapperaTime:1.0 andDis:nil];
            
        }else{
            _PersonalProblemLabel.hidden = textView.text.length > 0 ? YES:NO;
            
        }
    }
}

#pragma mark - 个性、共性问题
- (IBAction)PublicCharacter:(UIButton *)sender {
    
    self.TempButton = sender;
    // 删除
    if (sender.selected == YES) {
        
        [self AlertControllerOfTitle:@"是否删除该文件?" StringArr:@[@"确定"] CallBack:^(NSInteger Index, NSString *Str) {
            sender.selected = NO;
            if (sender == _CommonAudio) {
                _CommonAudioID = @"";
            }
            if (sender == _PersonalAudio) {
                _PersonalAudioID = @"";
            }
        }];
        return;
    }
    
    // 加
    [self AlertControllerOfTitle:@"请选择操作项" StringArr:@[@"图片上传", @"音频上传"] CallBack:^(NSInteger Index, NSString *Str) {
        
        // 图片
        if ([Str isEqualToString:@"图片上传"] && Index == 0) {
            
            [self ClickImage:sender];
        }
        
        // 音频
        if ([Str isEqualToString:@"音频上传"] && Index == 1) {
            
            [self ClickAudio:sender];
        }
        
    }];
}

#pragma mark - Get
- (CourseEvaluateUploadFileTool *)Tool
{
    if (!_Tool)
    {
        _Tool = [[CourseEvaluateUploadFileTool alloc] init];
    }
    return _Tool;
}

- (NSMutableArray<CourseEvaluateThreeGoodModel *> *)ThreeGoodArr
{
    if (!_ThreeGoodArr)
    {
        _ThreeGoodArr = [NSMutableArray array];
    }
    return _ThreeGoodArr;
}

- (NSMutableArray<NSString *> *)ThreeGoodSelectArr
{
    if (!_ThreeGoodSelectArr)
    {
        _ThreeGoodSelectArr = [NSMutableArray array];
    }
    return _ThreeGoodSelectArr;
}

- (UIImagePickerController *)ImagePicker
{
    if (!_ImagePicker)
    {
        _ImagePicker = [[UIImagePickerController alloc] init];
        _ImagePicker.delegate = self;
        _ImagePicker.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
        _ImagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        _ImagePicker.navigationBar.tintColor = [UIColor whiteColor];
        _ImagePicker.navigationBar.barTintColor = [UIColor colorWithRed:20.f/255.0 green:24.0/255.0 blue:38.0/255.0 alpha:1];
    }
    return _ImagePicker;
}

- (NSMutableArray<UIButton *> *)ImgBtns {
    
    if (!_ImgBtns) {
        
        _ImgBtns = [NSMutableArray array];
    }
    return _ImgBtns;
}

- (NSMutableArray *)ImgArr
{
    if (!_ImgArr)
    {
        _ImgArr = [NSMutableArray array];
    }
    return _ImgArr;
}

- (NSMutableArray *)VideoDict {
    
    if (!_VideoDict) {
        
        _VideoDict = [NSMutableArray array];
    }
    return _VideoDict;
}

- (BOOL)isSimulator {
#if TARGET_OS_SIMULATOR
    return YES;
#else
    return NO;
#endif
}





#pragma mark - 修改
/** 更改UI */
- (void)UpdataUI {
    
    // 好习惯
    [_DetailModel.HaoXiGuan_Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 加入豪华午餐
        [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
    }];
    [self ConfigGoodHabit];

    
    // 好成绩
    [_DetailModel.HaoChengJi_Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 加入豪华午餐
        [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
    }];
    [self ConfigGoodSource];

    // 好素养
    [_DetailModel.HaoSuYang_Arr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        // 加入豪华午餐
        [self.ThreeGoodArr addObject:[CourseEvaluateThreeGoodModel HNObjectValuesForKey:(NSDictionary *)obj]];
    }];
    [self ConfigGoodAttainment];
    
    // 按钮
    [_DetailModel.ImgF_Arr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIButton *Button = [self CreatImgBtn:nil];
        if ([[obj pathExtension] isEqualToString:@"amr"]) {
            
            [Button setBackgroundImage:[UIImage imageNamed:@"btn_mp3"] forState:Button.state];
        } else {
            [Button sd_setBackgroundImageWithURL:[NSURL URLWithString:obj] forState:Button.state placeholderImage:[UIImage imageNamed:@"image_user_default"]];
        }
            [self.ImgArr addObject:@{_DetailModel.ImgFID_Arr[idx]:Button}];
    }];
    
    // 共性、个性
    _CommonProblem.text = _DetailModel.commonProblem;
    _PersonalProblem.text = _DetailModel.personalProblem;
    [self textViewDidChange:_CommonProblem];
    [self textViewDidChange:_PersonalProblem];
    
    if (_DetailModel.commonF.length > 0) {
        [_CommonAudio sd_setBackgroundImageWithURL:[NSURL URLWithString:_DetailModel.commonF] forState:_CommonAudio.state placeholderImage:[UIImage imageNamed:@"btn_add_Three_Good"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            _CommonAudio.selected = YES;
        }];
    }
    
    if (_DetailModel.personalF.length > 0) {
        [_PersonalAudio sd_setBackgroundImageWithURL:[NSURL URLWithString:_DetailModel.personalF] forState:_PersonalAudio.state placeholderImage:[UIImage imageNamed:@"btn_add_Three_Good"] completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
            _PersonalAudio.selected = YES;
        }];
    }
    
    
    // 视频
    [_DetailModel.UrlArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIButton *Button = [self CreatImgBtn:nil];
        
        Button.backgroundColor = [UIColor redColor];
        [Button zy_setBackgroundImageWithUrl:_DetailModel.UrlImgArr[idx]];
        // 视频的存储，@[@{Button.tag:@{@"url":url,@"img":img}}]
        [self.VideoDict addObject:@{@(Button.tag):@{@"url":obj,@"img":_DetailModel.UrlImgArr[idx]}}];
    }];
}
@end
